Using Task Scheduler To Delete Files Over the age of X Days
نوشته شده توسط : jiajiasnow

You can use the Windows task scheduler to automatically delete files older than numerous days. Here's how you can get it done in simple steps.

To delete personal files or files in Windows, all you need to do is select them and press the delete button in your keyboard. For special folders like the downloads folder, trash can, cache folders, temp folders, etc., Windows includes a built-in tool called Storage Sense that can automatically delete files following a certain number of days. For example, if you wish to delete files after 30 days, Two months, or 90 days, you can configure Storage Sense to do just that. The downside is that the Storage Sense tool doesn't support custom folders.

So, to automatically delete files older than X number of days, make use of the job scheduler. Because the task scheduler enables you to execute scripts in a specific time, all we have to do is produce a custom script, add it to the job scheduler and then execute it as and when needed. The good thing is, we will use a simple PowerShell script to delete files older than numerous days. The script/command itself is pretty clear to see and configure.

With little delay, let me show you the steps to make use of task scheduler to delete files over the age of numerous days in Windows 10.

Use task scheduler to delete files older than X days

Open task scheduler.
Click on "Create Basic Task."
Name the brand new task.
Click "Next".
Select a trigger.
Configure selected trigger.
Select "Start a course."
Type "powershell" in the Program/Script field.
Paste the below command within the "Add arguments" field. Replace FOLDER_PATH & NUMBER_OF_DAYS with the actual folder path and number of days($_.LastWriteTime -lt (Get-Date).AddDays(-NUMBER_OF_DAYS))the job scheduler window.

First, open the Task Scheduler in Windows. You can do that by looking it up in the Start menu or by executing the "taskschd.msc" run command.

Once the task scheduler has been opened, click on the "Create Basic Task" option around the sidebar to create a new scheduled task.

Name the new task anything you want and click on "Next." Just be sure the name is descriptive enough. For example, if you wish to delete files older than Thirty days, name the job as a result.

Now, select when you wish the job to start and click "Next." With my case, I want the task to begin every day. So, I select the "Daily" option. If you want another thing, choose accordingly.

Configure the trigger you selected and click on "Next". Depending on the trigger you chose in the earlier step, this screen might be a bit different. For instance, since I chose "Daily", I have to set the actual time, start date, and just how usually the task should recur.

Since you want to operate a PowerShell command, choose the "Start a program" option. Click "Next" to carry on.

We further need to configure the "Start a program" action. So, complete($_.LastWriteTime -lt (Get-Date).AddDays(-NUMBER_OF_DAYS))using the actual folder path in which the files you need to delete are located. Also, replace NUMBER_OF_DAYS with the actual length of time. For example, if you would like the command to delete files over the age of Thirty days then replace NUMBER_OF_DAYS with 30. This is how the modified command appears like($_.LastWriteTime -lt (Get-Date).AddDays(-30))Review the summary window and click on the "Finish" button to complete the task creation process.

Finally, we are able to test the task to ascertain if it's being employed as intended. To achieve that, discover the task in the Task Scheduler window, right-click onto it and choose the "Run" option. You will see a brief flash of the PowerShell command window and also the files ought to be deleted.

Important note: All files are deleted permanently. i.e, they aren't gone to live in the recycle bin. If the files have been in use or locked by some other program, the PowerShell command might fail to delete one or more files. It could even get angry and throw errors. So, make sure the files will not be in use once the task is executed.





:: بازدید از این مطلب : 327
|
امتیاز مطلب : 0
|
تعداد امتیازدهندگان : 0
|
مجموع امتیاز : 0
تاریخ انتشار : جمعه 8 اسفند 1399 | نظرات ()
مطالب مرتبط با این پست
لیست
می توانید دیدگاه خود را بنویسید


نام
آدرس ایمیل
وب سایت/بلاگ
:) :( ;) :D
;)) :X :? :P
:* =(( :O };-
:B /:) =DD :S
-) :-(( :-| :-))
نظر خصوصی

 کد را وارد نمایید:

آپلود عکس دلخواه: